let numStr:string|number='1ayeh'

//断言
let str='arbga'
let strLength:number=(str as string).length

//void
function warnUser(): void {
    console.log("This is my warning message");
}

//定义数组
let arr1:number[]=[1,2,3,4]
let arr2:Array<number>=[5,6,7,8]

//求和函数
function fun(arr:number[]){
    let sum=0
    arr.forEach(item=>{
       return sum+=item
    })
    return sum
}
console.log(fun([2,8,9,6,5,8,7]),1111)

//判断boolean
function booleanFun(boo:any){
    return typeof(boo)=='boolean'
}

console.log(booleanFun(undefined),'boolean')

//计数
function strCount(str:string,val:string){
    let strnum=0;
    str.split('').forEach(item=>{
        if(item==val){
            strnum++
        }
    })
    return strnum
}
console.log(strCount('augiabaa','a'),'strcount')

//x5
function fun5(arr:(number|string)[]){
    let newfun5:number[]=[]
    arr.forEach(value => {
        if(typeof(value)=='number'){
            newfun5.push(value*5)
        }
    })
    return newfun5
}

console.log(fun5(['s',5,'g',3]),'fun5ji')

//补零
function fun6(arr:number[]){
    let newfun6:(string|number)[]=[]

    arr.forEach(item=>{
        if(item<=9&&item>=0){
            newfun6.push('0'+item)
        }else{
            newfun6.push(item)
        }
    })

    return newfun6
}

console.log(fun6([2,10,5,8,11]),'000')